// 缓存优化
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
const { NODE_ENV } = process.env;

const test =
  NODE_ENV === "development"
    ? [{ test: /[\\/]src[\\/]/ }]
    : [
        { test: /[\\/]mini-css-extract-plugin[\\/]dist[\\/]loader/ },
        { test: /[\\/]file-loader[\\/]/ },
        { test: /[\\/]url-loader[\\/]/ }
      ];

module.exports = (config) => {
  // cache
  config.cache(true);
  config.plugin("hard-source").use(HardSourceWebpackPlugin);
  config
    .plugin("hard-source-exclude")
    .use(HardSourceWebpackPlugin.ExcludeModulePlugin, test);
};
